var axios = require("axios");

module.exports = {
    namespaced: true,
    state: {
        // 库存信息
        UserList:[],
    },
    mutations: {
        getAllList(state,payload){
            payload.forEach(item => {
                if(item.authentication == '1'){
                    item.authentication = '审核通过'
                }else if (item.authentication == '0'){
                    item.authentication = '审核未通过'
                }
            });
            state.UserList = payload
        }
    },
    actions: {
        // 获取所有用户
        getAllUser(context,state){
            axios.get('/user/getUserAll',{params:{type:state}}).then(res => {
                 context.commit('getAllList',res.data)
             })
        },
        // 搜索用户
        serchUser(context,data){
            const {input,value,rent} = data
            axios.get('/user/serchUserAll',{params:{value,input,rent}}).then(res => {
                context.commit('getAllList',res.data)
            })
        },
        // 审核请求
        requestUserByAuthentication(context,index){
            const id = context.state.UserList[index]._id
            axios.put('/user/putUserState',{id}).then(res => {
                context.commit('getAllList',res.data)
            })
        }
    },
}